package com.jic.member.controller.power;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.common.util.BeanUtil;
import com.jic.member.entity.power.MememberRecipientInformation;
import com.jic.member.request.power.MemberRecipientInformationRequest;
import com.jic.member.response.power.MemberRecipientInformationResponse;
import com.jic.member.service.power.MememberRecipientInformationService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@ApiOperation(value = "会员收货信息controller")
@RestController
@RequestMapping("/recipient")
@Slf4j
public class MemberRecipientInformationController {

    @Autowired
    MememberRecipientInformationService memberRecipientInformation;

    /*
     * 分页查询
     * */
    @ApiOperation(value = "获取收货信息所有列表")
    @ResponseBody
    @RequestMapping("/queryRecipientInformationList")
    public RestResult<PageResult<MemberRecipientInformationResponse>> queryRecipientInformationList(@RequestBody MemberRecipientInformationRequest form) {
        log.info("开始进入收货信息列表=========》,{}", form.toString());
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        MememberRecipientInformation memberRequest = BeanUtil.copy(form, MememberRecipientInformation.class);
        PageResult<MememberRecipientInformation> result = memberRecipientInformation.queryPage(memberRequest, page);
        List<MemberRecipientInformationResponse> memberResponseList = result.getRows().stream().map(temp -> {
            MemberRecipientInformationResponse memberResponse = BeanUtil.copy(temp, MemberRecipientInformationResponse.class);
            return memberResponse;
        }).filter(item -> item != null).collect(Collectors.toList());

        PageResult<MemberRecipientInformationResponse> pageResult = new PageResult<>();
        pageResult.setRows(memberResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);
    }

}
